package com.sys.server.common.model;

import com.sys.server.common.constants.enums.ResultSetEnum;

import java.io.Serializable;
import java.util.HashMap;

/**
 * 返回结果封装
 *
 * @author shanbingzhen
 * @date 2022-01-10 10:00
 */
public class R extends HashMap<String, Object> implements Serializable {

    public final String code = "code";

    public final String msg = "msg";

    private final String data = "data";

    public R() { }

    public static R ok(Integer code, String msg) {
        R r = new R();
        r.put(r.code, code);
        r.put(r.msg, msg);
        return r;
    }

    public static R ok(ResultSetEnum result) {
        R r = new R();
        r.put(r.code, result.getCode());
        r.put(r.msg, result.getMsg());
        return r;
    }

    public static R ok(ResultSetEnum result, Object data) {
        R r = new R();
        r.put(r.code, result.getCode());
        r.put(r.msg, result.getMsg());
        r.put(r.data, data);
        return r;
    }

}
